package com.taotao.manage.controller.api;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;



import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;

import com.taotao.manage.pojo.Content;
import com.taotao.manage.service.ContentService;

@Controller
@RequestMapping("api/content")
public class ApiContentController {
	@Autowired
	private ContentService contentService;
	/**
	 * 
	 * 分页查询
	 * @return
	 */
	@RequestMapping(method=RequestMethod.GET)
	public ResponseEntity<List<Content>> queryContentList(
			@RequestParam(value="categoryId") Long categoryId,
			@RequestParam(value="page",defaultValue="1")Integer pageNum,
			@RequestParam(value="rows",defaultValue="10")Integer pageSize
			){
		try {
			Content record = new Content();
			record.setCategoryId(categoryId);
			//分页查询和排序
			PageInfo<Content> pageInfo = this.contentService.queryPageListByWhere(record , pageNum, pageSize);
			//判断
			if (pageInfo==null || pageInfo.getSize()!=0) {
				//201
				return  ResponseEntity.ok(pageInfo.getList());
			}
			
			return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//500异常
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
}

